﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using System8ToyMC;

namespace t_System8ToyMCControls
{
    [TestClass]
    public class t_System8Parameters : PresentationTest
    {
        System8Parameters _val;
        System8Equations.S8Equations _eqns;

        FlavorSampleUC _n, _p, _n1, _n2, _p1, _p2, _n12, _p12;

        EfficiencyUC _eff_LT_n, _eff_SMT_n, _eff_LT_p, _eff_SMT_p;
        EfficiencyUC _eff_away;
        EfficiencyUC _eff_SMTLT_n, _eff_SMTLT_p;

        AlphaUC _alpha_LT_p_n, _alpha_SMT_p_n;
        AlphaUC _alpha_SMTLT_p, _alpha_SMTLT_n;

        System8ResultsUC _results;

        [TestInitialize]
        public void InitMe()
        {
            _val = new System8Parameters();
            _eqns = new System8Equations.S8Equations();
            _val.Equations = _eqns;

            ///
            /// Grab all the flavor samples
            /// 

            _n = _val.FindName("f_n") as FlavorSampleUC;
            _n1 = _val.FindName("f_n1") as FlavorSampleUC;
            _n2 = _val.FindName("f_n2") as FlavorSampleUC;
            _n12 = _val.FindName("f_n12") as FlavorSampleUC;

            _p = _val.FindName("f_p") as FlavorSampleUC;
            _p1 = _val.FindName("f_p1") as FlavorSampleUC;
            _p2 = _val.FindName("f_p2") as FlavorSampleUC;
            _p12 = _val.FindName("f_p12") as FlavorSampleUC;

            ///
            /// Grab all the efficiencies
            /// 

            _eff_LT_n = _val.FindName("eff_LT_n") as EfficiencyUC;
            _eff_LT_p = _val.FindName("eff_LT_p") as EfficiencyUC;
            _eff_SMT_n = _val.FindName("eff_SMT_n") as EfficiencyUC;
            _eff_SMT_p = _val.FindName("eff_SMT_p") as EfficiencyUC;
            _eff_away = _val.FindName("eff_away") as EfficiencyUC;
            _eff_SMTLT_n = _val.FindName("eff_SMTLT_n") as EfficiencyUC;
            _eff_SMTLT_p = _val.FindName("eff_SMTLT_p") as EfficiencyUC;

            ///
            /// And the alphas, finally
            /// 

            _alpha_LT_p_n = _val.FindName("alpha_LT_p_n") as AlphaUC;
            _alpha_SMT_p_n = _val.FindName("alpha_SMT_p_n") as AlphaUC;
            _alpha_SMTLT_n = _val.FindName("alpha_SMTLT_n") as AlphaUC;
            _alpha_SMTLT_p = _val.FindName("alpha_SMTLT_p") as AlphaUC;

            ///
            /// Results!
            /// 

            _results = _val.FindName("results") as System8ResultsUC;
        }

        [TestMethod]
        public void TestCTor()
        {
        }

        [TestMethod]
        public void TestPath()
        {
            Assert.AreEqual("n", _n.Path, "n path is not right");
            Assert.AreEqual("p", _p.Path, "p path is not right");
            Assert.AreEqual("n1", _n1.Path, "n path is not right");
            Assert.AreEqual("p1", _p1.Path, "p path is not right");
            Assert.AreEqual("n2", _n2.Path, "n path is not right");
            Assert.AreEqual("p2", _p2.Path, "p path is not right");
            Assert.AreEqual("n12", _n12.Path, "n path is not right");
            Assert.AreEqual("p12", _p12.Path, "p path is not right");

            Assert.AreEqual("eff_LT_n", _eff_LT_n.Path, "eff_LT_n is not right");
            Assert.AreEqual("eff_LT_p", _eff_LT_p.Path, "eff_LT_p is not right");
            Assert.AreEqual("eff_SMT_n", _eff_SMT_n.Path, "eff_SMT_n is not right");
            Assert.AreEqual("eff_SMT_p", _eff_SMT_p.Path, "eff_SMT_p is not right");
            Assert.AreEqual("eff_SMTLT_n", _eff_SMTLT_n.Path, "eff_SMTLT_n is not right");
            Assert.AreEqual("eff_SMTLT_p", _eff_SMTLT_p.Path, "eff_SMTLT_p is not right");
            Assert.AreEqual("eff_away", _eff_away.Path, "eff_away is not right");

            Assert.AreEqual("alpha_LT_p_n", _alpha_LT_p_n.Path, "alpha_LT_p_n is nto right");
            Assert.AreEqual("alpha_SMT_p_n", _alpha_SMT_p_n.Path, "alpha_LT_p_n is nto right");
            Assert.AreEqual("alpha_SMTLT_p", _alpha_SMTLT_p.Path, "alpha_SMTLT_p is nto right");
            Assert.AreEqual("alpha_SMTLT_n", _alpha_SMTLT_n.Path, "alpha_SMTLT_n is nto right");
            Assert.AreEqual("results", _results.Path, "results aren't set right");

        }

        [TestMethod]
        public void TestAllThere()
        {
            Assert.IsNotNull(_n, "n is missing");
            Assert.IsNotNull(_n1, "n1 is missing");
            Assert.IsNotNull(_n2, "n2 is missing");
            Assert.IsNotNull(_n12, "n12 is missing");

            Assert.IsNotNull(_p, "p is missing");
            Assert.IsNotNull(_p1, "p1 is missing");
            Assert.IsNotNull(_p2, "p2 is missing");
            Assert.IsNotNull(_p12, "p12 is missing");

            Assert.IsNotNull(_eff_LT_n, "eff lt n is missing");
            Assert.IsNotNull(_eff_LT_p, "eff lt p is missing");
            Assert.IsNotNull(_eff_SMT_n, "eff smt n is missing");
            Assert.IsNotNull(_eff_SMT_p, "eff smt p is missing");
            Assert.IsNotNull(_eff_SMTLT_n, "eff smtlt n is mising");
            Assert.IsNotNull(_eff_SMTLT_p, "eff smtlt p is missing");
            Assert.IsNotNull(_eff_away, "eff smtlt p is missing");

            Assert.IsNotNull(_alpha_LT_p_n, "alpha lt p n is missing");
            Assert.IsNotNull(_alpha_SMT_p_n, "alpha smt p n is missing");
            Assert.IsNotNull(_alpha_SMTLT_n, "alpha smtlt n is missing");
            Assert.IsNotNull(_alpha_SMTLT_p, "alpha smtlt p is missing");

            Assert.IsNotNull(_results, "results is missing");
        }

        [TestMethod]
        public void TestHookupBinding()
        {
            Assert.IsNotNull(_n.FlavorInfo, "n has null dependencies");
            Assert.IsNotNull(_p.FlavorInfo, "p has null dependencies");
            Assert.IsNotNull(_p1.FlavorInfo, "p1 has null dependencies");
            Assert.IsNotNull(_n1.FlavorInfo, "n1 has null dependencies");
            Assert.IsNotNull(_p2.FlavorInfo, "p2 has null dependencies");
            Assert.IsNotNull(_n2.FlavorInfo, "n2 has null dependencies");
            Assert.IsNotNull(_p12.FlavorInfo, "p12 has null dependencies");
            Assert.IsNotNull(_n12.FlavorInfo, "n12 has null dependencies");

            Assert.IsNotNull(_eff_LT_n.Efficiency, "eff_lt_n has null dependencies");
            Assert.IsNotNull(_eff_LT_p.Efficiency, "eff_lt_p has null dependencies");
            Assert.IsNotNull(_eff_SMT_n.Efficiency, "eff_SMT_n has null dependencies");
            Assert.IsNotNull(_eff_SMT_p.Efficiency, "eff_SMT_p has null dependencies");
            Assert.IsNotNull(_eff_SMTLT_n.Efficiency, "eff_smtlt_n has null dependencies");
            Assert.IsNotNull(_eff_SMTLT_p.Efficiency, "eff_smtlt_p has null dependencies");
            Assert.IsNotNull(_eff_away.Efficiency, "eff_away has null dependencies");

            Assert.IsNotNull(_alpha_LT_p_n.AlphaValue, "alpha lt p n is missing");
            Assert.IsNotNull(_alpha_SMT_p_n.AlphaValue, "alpha smt p n is missing");
            Assert.IsNotNull(_alpha_SMTLT_n.AlphaValue, "alpha smtlt n is missing");
            Assert.IsNotNull(_alpha_SMTLT_p.AlphaValue, "alpha smtlt p is missing");

            Assert.IsNotNull(_eff_LT_n.EpsilonCL, "eff_lt_n has null dependencies cl");
            Assert.IsNotNull(_eff_LT_p.EpsilonCL, "eff_lt_p has null dependencies cl");
            Assert.IsNotNull(_eff_SMT_n.EpsilonCL, "eff_SMT_n has null dependencies cl");
            Assert.IsNotNull(_eff_SMT_p.EpsilonCL, "eff_SMT_p has null dependencies cl");
            Assert.IsNotNull(_eff_SMTLT_n.EpsilonCL, "eff_smtlt_n has null dependencies cl");
            Assert.IsNotNull(_eff_SMTLT_p.EpsilonCL, "eff_smtlt_p has null dependencies cl");
            Assert.IsNotNull(_eff_away.EpsilonCL, "eff_away has null dependencies cl");

            Assert.IsNotNull(_alpha_LT_p_n.Alpha12Value, "alpha lt p n is missing cl");
            Assert.IsNotNull(_alpha_SMT_p_n.Alpha12Value, "alpha smt p n is missing cl");

            Assert.IsNotNull(_results.System8R, "results system 8 is null!");

            /// Not clear what we should have here.
            //Assert.IsNotNull(_alpha_SMTLT_n.Alpha12Value, "alpha smtlt n is missing cl");
            //Assert.IsNotNull(_alpha_SMTLT_p.Alpha12Value, "alpha smtlt p is missing cl");
        }

        /// <summary>
        /// Set something in our system8 guy and make sure it shows up in the
        /// display! Ugh, this is a mess!
        /// </summary>
        [TestMethod]
        public void TestSettingValues()
        {
            _eqns.n.Bottom = 100;
            Assert.AreEqual(100.0, _n.FlavorInfo.Bottom, "The bottom value didn't get set correctly");
            _eqns.p.Bottom = 100;
            Assert.AreEqual(100.0, _p.FlavorInfo.Bottom, "Expected the p setting to be 100!");
            _eqns.n1.Bottom = 100;
            Assert.AreEqual(100.0, _n1.FlavorInfo.Bottom, "The bottom rate didn't get set correctly");
            _eqns.p1.Bottom = 100;
            Assert.AreEqual(100.0, _p1.FlavorInfo.Bottom, "Expected the p setting to be 100!");
            _eqns.n2.Bottom = 100;
            Assert.AreEqual(100.0, _n1.FlavorInfo.Bottom, "The bottom rate didn't get set correctly");
            _eqns.p2.Bottom = 100;
            Assert.AreEqual(100.0, _p1.FlavorInfo.Bottom, "Expected the p setting to be 100!");
            _eqns.n12.Bottom = 100;
            Assert.AreEqual(100.0, _n1.FlavorInfo.Bottom, "The bottom rate didn't get set correctly");
            _eqns.p12.Bottom = 100;
            Assert.AreEqual(100.0, _p1.FlavorInfo.Bottom, "Expected the p setting to be 100!");
        }

        [TestMethod]
        public void TestSettingSourceValues()
        {
            _n.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.n.Bottom, "The bottom value didn't get set correctly b");
            _p.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.p.Bottom, "Expected the p setting to be 100!");
            _n1.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.n1.Bottom, "The bottom rate didn't get set correctly n1");
            _p1.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.p1.Bottom, "Expected the p1 setting to be 100!");
            _n2.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.n2.Bottom, "The bottom rate didn't get set correctly n2");
            _p2.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.p2.Bottom, "Expected the p2 setting to be 100!");
            _n12.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.n12.Bottom, "The bottom rate didn't get set correctly n12");
            _p12.FlavorInfo.Bottom = 100;
            Assert.AreEqual(100.0, _eqns.p12.Bottom, "Expected the p setting to be 100! p12");
        }

        [TestMethod]
        public void TestSettingEff()
        {
            _eqns.eff_away.eff_b = 0.5;
            Assert.AreEqual(0.5, _eff_away.Efficiency.eff_b, "eff away The bottom rate didn't get set correctly");
            _eqns.eff_LT_n.eff_b = 0.5;
            Assert.AreEqual(0.5, _eff_LT_n.Efficiency.eff_b, "eff lt n The bottom rate didn't get set correctly");
            _eqns.eff_LT_p.eff_b = 0.5;
            Assert.AreEqual(0.5, _eff_LT_p.Efficiency.eff_b, "eff lt p The bottom rate didn't get set correctly");
            _eqns.eff_SMT_n.eff_b = 0.5;
            Assert.AreEqual(0.5, _eff_SMT_n.Efficiency.eff_b, "eff smt n The bottom rate didn't get set correctly");
            _eqns.eff_SMT_p.eff_b = 0.5;
            Assert.AreEqual(0.5, _eff_SMT_p.Efficiency.eff_b, "eff smt p The bottom rate didn't get set correctly");
            _eqns.eff_SMTLT_n.eff_b = 0.25;
            Assert.AreEqual(0.25, _eff_SMTLT_n.Efficiency.eff_b, "eff smtlt n The bottom rate didn't get set correctly");
            _eqns.eff_SMTLT_p.eff_b = 0.25;
            Assert.AreEqual(0.25, _eff_SMTLT_p.Efficiency.eff_b, "eff smtlt p The bottom rate didn't get set correctly");
        }

        [TestMethod]
        public void TestSettingSourceEff()
        {
            _eff_away.Efficiency.eff_b = 0.5;
            Assert.AreEqual(0.5, _eqns.eff_away.eff_b, "eff away The bottom rate didn't get set correctly");
            _eff_LT_n.Efficiency.eff_b = 0.5;
            Assert.AreEqual(0.5, _eqns.eff_LT_n.eff_b, "eff lt n The bottom rate didn't get set correctly");
            _eff_LT_p.Efficiency.eff_b = 0.5;
            Assert.AreEqual(0.5, _eqns.eff_LT_p.eff_b, "eff lt p The bottom rate didn't get set correctly");
            _eff_SMT_n.Efficiency.eff_b = 0.5;
            Assert.AreEqual(0.5, _eqns.eff_SMT_n.eff_b, "eff smt n The bottom rate didn't get set correctly");
            _eff_SMT_p.Efficiency.eff_b = 0.5;
            Assert.AreEqual(0.5, _eqns.eff_SMT_p.eff_b, "eff smt p The bottom rate didn't get set correctly");
            _eff_SMTLT_n.Efficiency.eff_b = 0.25;
            Assert.AreEqual(0.25, _eqns.eff_SMTLT_n.eff_b, "eff smtlt n The bottom rate didn't get set correctly");
            _eff_SMTLT_p.Efficiency.eff_b = 0.25;
            Assert.AreEqual(0.25, _eqns.eff_SMTLT_p.eff_b, "eff smtlt p The bottom rate didn't get set correctly");
        }

        [TestMethod]
        public void TestSettingAlphas()
        {

            _eqns.alpha_LT_p_n.alpha_b = 0.9;
            Assert.AreEqual(0.9, _alpha_LT_p_n.AlphaValue.alpha_b, "Expected alpha lt p n b to be set correctly");
            _eqns.alpha_SMT_p_n.alpha_b = 0.9;
            Assert.AreEqual(0.9, _alpha_SMT_p_n.AlphaValue.alpha_b, "Expected alpha smt p n b to be set correctly");

            _eqns.alpha_SMTLT_n.alpha_b = 0.9;
            Assert.AreEqual(0.9, _alpha_SMTLT_n.AlphaValue.alpha_b, "alpha smtlt n not set right");
            _eqns.alpha_SMTLT_p.alpha_b = 0.9;
            Assert.AreEqual(0.9, _alpha_SMTLT_p.AlphaValue.alpha_b, "alpha smtlt p not set right");
        }

        [TestMethod]
        public void TestSettingSourceAlphas()
        {
            _alpha_LT_p_n.AlphaValue.alpha_b = 0.9;
            Assert.AreEqual(0.9, _eqns.alpha_LT_p_n.alpha_b, "Expected alpha lt p n b to be set correctly");
            _alpha_SMT_p_n.AlphaValue.alpha_b = 0.9;
            Assert.AreEqual(0.9, _eqns.alpha_SMT_p_n.alpha_b, "Expected alpha SMT p n b to be set correctly");

            _alpha_SMTLT_n.AlphaValue.alpha_b = 0.9;
            Assert.AreEqual(0.9, _eqns.alpha_SMTLT_n.alpha_b, "alpha smtlt n not set right");
            _alpha_SMTLT_p.AlphaValue.alpha_b = 0.9;
            Assert.AreEqual(0.9, _eqns.alpha_SMTLT_p.alpha_b, "alpha smtlt p not set right");
        }
    }
}